/**
 * Created by DevilsEyes on 2016/4/22.
 */
//studentVerify
define([], function () {
    'use strict';

    var vm = avalon.define({
        $id: 'studentVerify',
        list: [],
        limit: 20,
        check: [],
        getList: function () {
            $.ajax({
                url: '/api/admin/user/verify/list',
                data: {
                    limit: vm.limit,
                    index: vm.list.length
                },
                success: function (data) {
                    vm.list = data.list;
                    setTimeout(function () {
                        $('[data-toggle="checkbox"]').radiocheck();
                    }, 0)
                }
            })
        },
        allSelect: function () {
            vm.check = vm.list.map(function (v) {
                return v.id;
            })
        },
        reserveSelect: function () {
            var temp = vm.list.reduce(function (last, v) {

                if (vm.check.some(function (check) {
                        return check == v.id;
                    })) {
                    return last;
                } else {
                    return last.concat([v.id]);
                }

            }, []);
            vm.check = temp;
        },
        verify: function ($event, status) {
            if (vm.check.length == 0)return;
            $.ajax({
                url: "/api/admin/user/verify",
                method: 'POST',
                traditional: true,
                data: {
                    json: JSON.stringify({
                        list: vm.check.map(function (v) {
                            return v
                        }),
                        pass: status
                    })
                },
                success: function (res) {
                    if (res.code == 0) {
                        alert('操作完成');
                    } else {
                        alert(res.msg);
                    }
                }
            })
        }
    });

    return {
        init: function () {
            vm.list = [];
            vm.getList();
            // $root.page = temp;
        }
    }
});
